import java.util.Scanner;

/**
 * 功能描述
 *
 * @author w00586986
 * @since 2022-05-20
 */
enum ExceptionEnum {
    ARITHMETIC(new ArithmeticException()),
    INDEXOUTOFBOUNDS(new IndexOutOfBoundsException()),
    NEGATIVEARRAYSIZE(new NegativeArraySizeException()),
    NULLPOINTER(new NullPointerException()),
    NUMBERFORMAT(new NumberFormatException()),
    CLASSCAST(new ClassCastException());

    ExceptionEnum(Exception e) {
        this.e = e;
    }

    private Exception e;

    public Exception getException() {
        return e;
    }

    public static ExceptionEnum getExceptionByOrdinal(int ord) throws IllegalArgumentException {
        ExceptionEnum[] array = ExceptionEnum.values();
        if (ord >= array.length || ord < 0) {
            throw new IllegalArgumentException();
        }
        return array[ord];
    }
}
public class CommonExceptionDemo {
    public static void main(String[] args) {
        System.out.print("Please input an integer to select the TYPE OF EXCEPTION(0~5): ");
        Scanner input = new Scanner(System.in);
        int num;
        try {
            num = input.nextInt();
            throw ExceptionEnum.getExceptionByOrdinal(num).getException();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Here is the End.");
    }
}
